package com.zzjson.mall.util;

import java.io.Serializable;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2020 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : 云商城 </li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2020年10月21日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class RespResult<T> implements Serializable {
	private T data;

	/**
	 * 状态码
	 * 20000 操作成功
	 * 50000 操作失败
	 */
	private Integer code;

	/**
	 * 响应消息
	 */
	private String message;

	public RespResult() {
	}

	public RespResult(RespCode respCode) {
		this.code = respCode.getCode();
		this.message = respCode.getMessage();
	}

	public RespResult(T data, RespCode respCode) {
		this.data = data;
		this.code = respCode.getCode();
		this.message = respCode.getMessage();
	}

	public static RespResult ok() {
		return new RespResult(null, RespCode.SUCCESS);
	}

	public static RespResult ok(Object data) {
		return new RespResult(data, RespCode.SUCCESS);
	}

	public static RespResult error() {
		return new RespResult(null, RespCode.ERROR);
	}

	public static RespResult error(String message) {
		return secByError(RespCode.ERROR.getCode(), message);
	}

	//自定义异常
	public static RespResult secByError(Integer code, String message) {
		RespResult err = new RespResult();
		err.setCode(code);
		err.setMessage(message);
		return err;
	}

	public static RespResult error(RespCode resultCode) {
		return new RespResult(resultCode);
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}